import axios from 'axios'
import config from '../config/response'

const service = axios.create({
  baseURL: import.meta.env.VITE_BASE_URL
})

service.interceptors.request.use(config => {
  return config
}, error => {
  return Promise.reject(error)
})

service.interceptors.response.use(response => {
  const { data, code, msg } = response.data
  if (code === config.CODE_SUCCESS) {
    // 成功
    return data
  } else if (code === config.CODE_ERROR) {
    // 错误
  } else {
    // 未知错误, 基本上不存在这种
  }
}, error => {
  console.log(error)
})

export default service
